package com.le.edu.controller;

import com.le.edu.domain.entity.Chapter;
import com.le.edu.domain.vo.ChapterInfoVO;
import com.le.edu.resp.Result;
import com.le.edu.service.ChapterService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Le
 * @create 2024-04-09 12:21
 */
@RestController
@RequiredArgsConstructor
@Tag(name = "章节接口")
@RequestMapping("/chapter")
public class ChapterController extends BaseController {
    private final ChapterService chapterService;

    /**
     * 封装章节和对应的课时
     *
     * @param courseId
     * @return
     */
    @Operation(summary = "根据课程id查询课程大纲")
    @GetMapping("/info/{courseId}")
    public Result<List<ChapterInfoVO>> getChapterAndSectionAndVideoList(@PathVariable("courseId") Long courseId) {
        return Result.ok(chapterService.getChapterAndSectionVoList(courseId));
    }

    @PostMapping
    @Operation(summary = "添加章节")
    public Result<Void> addChapter(@RequestBody Chapter chapter) {
        return toAjax(chapterService.save(chapter));
    }

    @PutMapping
    @Operation(summary = "修改章节")
    public Result<Void> updateChapter(@RequestBody Chapter chapter) {
        return toAjax(chapterService.updateById(chapter));
    }

    @Operation(summary = "通过章节id删除章节-课时-视频")
    @DeleteMapping("/{chapterId}")
    public Result<Void> delChapterAndSectionAndVideoByChapterId(@PathVariable("chapterId") Long chapterId) {
        chapterService.delChapterAndSectionAndVideoByChapterId(chapterId);
        return Result.ok();
    }

}
